package filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
//定义过滤器的名字以及过滤的对象
//@WebFilter(filterName = "FirstFilter",urlPatterns = {"/*.jsp"})
public class FirstFilter implements Filter{
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO 自动生成的方法存根
		System.out.println("first filter  ----initing");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO 自动生成的方法存根
		//防止出现乱码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		
		System.out.println("first filter --doFilter start");
		//过滤链向后传递
		chain.doFilter(request, response);
		System.out.println("first filter --doFilter end");
		
	}
	
	@Override
	public void destroy() {
		// TODO 自动生成的方法存根
		System.out.println("first filter---destroyed");
	}

}
